package daybook.io.args;

import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.ParameterException;
import daybook.io.formatter.Format;

import java.util.EnumSet;
import java.util.Set;

public class InputFormatValidator implements IParameterValidator {
    private static Set<Format> VALID_INPUT_FORMAT = EnumSet.of(Format.STRING, Format.JSON);
    @Override
    public void validate(String name, String value) throws ParameterException {
        try {
            final Format format = Format.valueOf(value.toUpperCase());
            if (!VALID_INPUT_FORMAT.contains(format)) {
                throw new ParameterException("not supported input format: " + value);
            }
        } catch (IllegalArgumentException e) {
            throw new ParameterException("not supported format: " + value);
        }
    }
}
